package com.kiloai.digcust.mvp.view.activity;

import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kiloai.base.basemvp.MVPBaseActivity;
import com.kiloai.base.custom.CustomSwipeRefreshLayout;
import com.kiloai.base.utils.PixelUtil;
import com.kiloai.digcust.R;
import com.kiloai.digcust.mvp.presenter.TalkListPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by david on 2018/8/20.
 */

public class TalkListActivity extends MVPBaseActivity<TalkListActivity, TalkListPresenter> {
    @BindView(R.id.fl_padding)
    FrameLayout flPadding;
    @BindView(R.id.tv_main)
    TextView tvMain;
    @BindView(R.id.rl_processMain)
    RelativeLayout rlProcessMain;
    @BindView(R.id.tv_qa)
    TextView tvQa;
    @BindView(R.id.rl_processQa)
    RelativeLayout rlProcessQa;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.swipeLayout)
    CustomSwipeRefreshLayout swipeLayout;
    private TalkListPresenter presenter;


    @Override
    protected TalkListPresenter createPresenter() {
        if (presenter == null) {
            presenter = new TalkListPresenter();
        }
        return presenter;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_talk_list);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        addPaddingView();
    }

    // android 4.4以上将Toolbar添加状态栏高度的上边距，沉浸到状态栏下方
    private void addPaddingView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            View view = new View(this);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, PixelUtil.getStatusHeight(this));
            view.setLayoutParams(params);
            flPadding.addView(view);
        }
    }

    @OnClick({R.id.rl_processMain, R.id.rl_processQa})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_processMain:
                break;
            case R.id.rl_processQa:
                break;
        }
    }

    private PopupWindow popupWindow;

    public void showPayPop(String title) {
        View view = LayoutInflater.from(this).inflate(R.layout.pop_record_paly, null);
        popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());//开启返回键
        popupWindow.setAnimationStyle(R.style.AnimPopWondows);
        popupWindow.setClippingEnabled(false);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.showAsDropDown(view);


        view.findViewById(R.id.empty_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
    }
}
